class Solution {
    public int maxProfit(int[] prices) {
        int ans = 0;
        for (int i = 1; i < prices.length; i++) {
            // 确保每一次涨价都赚钱就行了额
            ans += Math.max(prices[i] - prices[i-1], 0);
        }
        return ans;
    }
    private int regularMethod(int[] prices) {
        boolean haven = false;
        int profit = 0;
        int cost = 0;
        for (int i = 0; i < prices.length - 1; i++) {
            if (prices[i+1] < prices[i]) {
                // 跌
                if (haven) {
                    profit += prices[i] - cost;
                    haven = false;
                }
            } else if (prices[i+1] > prices[i]) {
                // 涨
                 if (!haven) {
                     cost = prices[i];
                     haven = true;
                 }
            }
        }
        if (haven) {
            profit += prices[prices.length - 1] - cost;
        }
        return profit;
    }
}
